//
//  YSServiceManager.m
//  luGongPro
//
//  Created by 王庆学 on 2017/7/31.
//  Copyright © 2017年 王庆学. All rights reserved.
//

#import "YSServiceManager.h"
#import "YSRequest.h"

@interface YSServiceManager ()

@property (nonatomic, copy) NSString *env;

@end

@implementation YSServiceManager

- (instancetype)init
{
    self = [super init];
    if (self){
#if TESTING == 1
        _mYSServiceType = YSServiceTypeTEST;
#elif TESTING == 2
        _mYSServiceType = YSServiceTypeDemo;
#else
        _mYSServiceType = YSServiceTypeProduct;
#endif
    
#if IOSDEBUG
        NSInteger mServiceType = [[NSUserDefaults standardUserDefaults] integerForKey:@"ySServiceType"];
        if (mServiceType != 0){
            _mYSServiceType = mServiceType;
        }
#endif
        }
    return self;
}

+ (instancetype) sharedServiceManager
{
    static YSServiceManager * shareManager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        shareManager = [[self alloc]init];
    });
    return shareManager;
}

- (void)registerServiceKey{
    [YSRequestConfig shared].serviceKey = self.env;
}

+ (void)registerServiceKey{
    [[[YSServiceManager alloc]init]registerServiceKey];
}

- (NSString *)env{
#if IOSDEBUG
    if (_mYSServiceType == YSServiceTypeProduct){
        return @"ys";
    }
    if (_mYSServiceType == YSServiceTypeTEST){
        return @"test_ys";
    }
    if (_mYSServiceType == YSServiceTypeDemo){
        return @"demo_ys";
    }
#else
    if (_env ==nil){
#if TESTING
        _env = @"test_ys";
#else
        _env = @"ys";
#endif
    }
    return _env;
#endif
    abort();
}

+ (NSString *)serviceId{
    return @"3004";
}

@end
